package com.michaelbulava.TFS.ui.config;

import com.michaelbulava.TFS.ui.dialogs.connect.ACSCredentialsDialog;
import com.michaelbulava.TFS.ui.dialogs.connect.CredentialsCompleteDialog;
import com.microsoft.tfs.core.util.URIUtils;
import com.microsoft.tfs.core.ws.runtime.exceptions.FederatedAuthException;
import com.microsoft.tfs.util.Check;

import java.net.URI;

/**
 * Created by mbulava on 6/26/2015.
 */
public class UITransportFederatedAuthRunnable extends UITransportAuthRunnable {

    private final URI serverURI;
    private final FederatedAuthException exception;

    public UITransportFederatedAuthRunnable(URI serverURI, FederatedAuthException exception) {
        Check.notNull(serverURI, "serverURI");
        Check.notNull(exception, "exception");

        this.serverURI = serverURI;
        this.exception = exception;
    }

    public boolean isAvailable() {
        //return ACSCredentialsDialog.isAvailable();
        return ACSCredentialsDialog.isAvailable();
    }

    @Override
    protected CredentialsCompleteDialog getCredentialsDialog() {
        return new ACSCredentialsDialog(null, this.serverURI, URIUtils.newURI(this.exception.getAuthenticationURL()),
                this.exception);
    }
}
